package com.blb.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blb.entity.Notes;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ZhengSanNan
 * @since 2019-12-20
 */
public interface NotesMapper extends BaseMapper<Notes> {


    @Select("SELECT * FROM t_notes WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= update_time AND recycle=0")
    public List<Notes> getNewNote();
    @Select("SELECT * FROM t_notes WHERE user_id=#{userid} ORDER BY favorite DESC, update_time DESC LIMIT 0,10 ")
    List<Notes> newnote(String userid);

    @Select("SELECT l.id,l.label_name,n.* FROM t_label l LEFT JOIN t_note_label nl ON nl.label_id = l.id LEFT JOIN t_notes n  ON nl.notes_id = n.id WHERE l.id = #{labelId} ")
    List<Notes> getNoteByLabelId(String labelId);

    List<Notes> getNoteListByNotesName(String notesName,String favorite,String userId);

    int getCount(String notesName,String favorite,String userId);



    /**
     * 根据没有父级查找所有笔记
     * @return
     */
    @Select("SELECT * FROM t_notes WHERE classification_id is NULL")
    List<Notes> getAllNotes();

    /**
     * 根据classification_id查询所有笔记
     * @return
     */
    @Select("SELECT * FROM t_notes WHERE classification_id=#{classificationId}")
    List<Notes> getAllNotesByClassId(String classificationId);



    @Select("SELECT * FROM t_notes WHERE user_id=#{userid} and id=#{id}")
    List<Notes> getOneNote(String userid,String id);

    /**
     *修改加信状态
     */
    @Update("UPDATE t_notes SET favorite=#{favorite} WHERE id=#{id}")
    public void updateStars(@Param("id") String id, @Param("favorite") String favorite);
    /**
     * 修改文件标题和内容
     */
    @Update("update t_notes set notes_name=#{notesName},content=#{content},update_time=#{date} where id=#{id}")
    public void updateNotes(@Param("id") String id,@Param("notesName") String notesName,@Param("content") String content,@Param("date") Date date);
    /**
     * 文件条件排序
     */
    List<Notes> sortNotes(@Param("types")String types,@Param("token")String token);



}
